<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>Excel处理之Openpyxl库 | Sep2Sevem'blog</title><meta name="author" content="Sep2Seven"><meta name="copyright" content="Sep2Seven"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="参考：https:&#x2F;&#x2F;blog.csdn.net&#x2F;weixin_43094965&#x2F;article&#x2F;details&#x2F;82226263 一 安装 1pip install openpyxl 二 打开文件（只支持xlsx格式） 1.创建 123456from  openpyxl import  Workbook # 实例化wb &#x3D; Workbook()# 激活 worksheetws &#x3D; wb.acti">
<meta property="og:type" content="article">
<meta property="og:title" content="Excel处理之Openpyxl库">
<meta property="og:url" content="http://sep2seven.blog.com/2023/06/08/ExcelOpenpyxl/index.html">
<meta property="og:site_name" content="Sep2Sevem&#39;blog">
<meta property="og:description" content="参考：https:&#x2F;&#x2F;blog.csdn.net&#x2F;weixin_43094965&#x2F;article&#x2F;details&#x2F;82226263 一 安装 1pip install openpyxl 二 打开文件（只支持xlsx格式） 1.创建 123456from  openpyxl import  Workbook # 实例化wb &#x3D; Workbook()# 激活 worksheetws &#x3D; wb.acti">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://sep2seven.blog.com/img/yanhua.jpg">
<meta property="article:published_time" content="2023-06-08T08:50:33.000Z">
<meta property="article:modified_time" content="2023-06-08T08:31:26.851Z">
<meta property="article:author" content="Sep2Seven">
<meta property="article:tag" content="Python">
<meta property="article:tag" content="Openpyxl">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://sep2seven.blog.com/img/yanhua.jpg"><link rel="shortcut icon" href="/img/boniu.jpg"><link rel="canonical" href="http://sep2seven.blog.com/2023/06/08/ExcelOpenpyxl/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//fonts.googleapis.com" crossorigin=""/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web&amp;display=swap" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":true,"top_n_per_article":1,"unescape":true,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: {"defaultEncoding":2,"translateDelay":1000,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":150},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"bottom-left"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Excel处理之Openpyxl库',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-06-08 16:31:26'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>(()=>{
  const $loadingBox = document.getElementById('loading-box')
  const $body = document.body
  const preloader = {
    endLoading: () => {
      $body.style.overflow = ''
      $loadingBox.classList.add('loaded')
    },
    initLoading: () => {
      $body.style.overflow = 'hidden'
      $loadingBox.classList.remove('loaded')
    }
  }

  preloader.initLoading()
  window.addEventListener('load',() => { preloader.endLoading() })

  if (false) {
    document.addEventListener('pjax:send', () => { preloader.initLoading() })
    document.addEventListener('pjax:complete', () => { preloader.endLoading() })
  }
})()</script><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/boniu.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">4</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">8</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li><li><a class="site-page child" href="/picture/"><i class="fa-fw fas fa-image"></i><span> 图库</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/img/yanhua.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="Sep2Sevem'blog"><span class="site-name">Sep2Sevem'blog</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li><li><a class="site-page child" href="/picture/"><i class="fa-fw fas fa-image"></i><span> 图库</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Excel处理之Openpyxl库</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-06-08T08:50:33.000Z" title="发表于 2023-06-08 16:50:33">2023-06-08</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-06-08T08:31:26.851Z" title="更新于 2023-06-08 16:31:26">2023-06-08</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Python%E5%AD%A6%E4%B9%A0%E8%AE%B0%E5%BD%95/">Python学习记录</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.1k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>9分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Excel处理之Openpyxl库"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><p>参考：<a target="_blank" rel="noopener" href="https://blog.csdn.net/weixin_43094965/article/details/82226263">https://blog.csdn.net/weixin_43094965/article/details/82226263</a></p>
<h4 id="一-安装">一 安装</h4>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pip install openpyxl</span><br></pre></td></tr></table></figure>
<h4 id="二-打开文件（只支持xlsx格式）">二 打开文件（只支持xlsx格式）</h4>
<h5 id="1-创建">1.创建</h5>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span>  openpyxl <span class="keyword">import</span>  Workbook </span><br><span class="line"><span class="comment"># 实例化</span></span><br><span class="line">wb = Workbook()</span><br><span class="line"><span class="comment"># 激活 worksheet</span></span><br><span class="line">ws = wb.active</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h5 id="2-打开已有文件">2.打开已有文件</h5>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&gt;&gt;&gt; </span><span class="keyword">from</span> openpyxl  <span class="keyword">import</span> load_workbook</span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>wb2 = load_workbook(<span class="string">&#x27;文件名称.xlsx&#x27;</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="三-表（sheet）">三 表（sheet）</h4>
<h5 id="1-创建表">1.创建表</h5>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 方式一：插入到最后(default)</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>ws1 = wb.create_sheet(<span class="string">&quot;Mysheet&quot;</span>) </span><br><span class="line"><span class="comment"># 方式二：插入到最开始的位置</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>ws2 = wb.create_sheet(<span class="string">&quot;Mysheet&quot;</span>, <span class="number">0</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h5 id="3-删除表">3.删除表</h5>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 方式一</span></span><br><span class="line">wb.remove(sheet)</span><br><span class="line"><span class="comment"># 方式二</span></span><br><span class="line"><span class="keyword">del</span> wb[sheet]</span><br></pre></td></tr></table></figure>
<h5 id="2-选择表">2.选择表</h5>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># sheet 名称可以作为 key 进行索引</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>ws3 = wb[<span class="string">&quot;New Title&quot;</span>]</span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>ws4 = wb.get_sheet_by_name(<span class="string">&quot;New Title&quot;</span>)</span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>ws <span class="keyword">is</span> ws3 <span class="keyword">is</span> ws4</span><br><span class="line"><span class="literal">True</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h5 id="3-查看表名">3.查看表名</h5>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 显示所有表名</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span><span class="built_in">print</span>(wb.sheetnames)</span><br><span class="line">[<span class="string">&#x27;Sheet2&#x27;</span>, <span class="string">&#x27;New Title&#x27;</span>,  <span class="string">&#x27;Sheet1&#x27;</span>]</span><br><span class="line"><span class="comment"># 遍历所有表</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span><span class="keyword">for</span> sheet <span class="keyword">in</span>  wb:</span><br><span class="line"><span class="meta">... </span>	<span class="built_in">print</span>(sheet.title)</span><br></pre></td></tr></table></figure>
<h4 id="三-单元格">三 单元格</h4>
<h5 id="1-单一单元格访问">1.单一单元格访问</h5>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 方法一</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>c = ws[<span class="string">&#x27;A4&#x27;</span>]</span><br><span class="line"><span class="comment"># 方法二：row 行；column 列</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>d = ws.cell(row=<span class="number">4</span>, column=<span class="number">2</span>, value=<span class="number">10</span>)</span><br><span class="line"><span class="comment"># 方法三：只要访问就创建</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span><span class="keyword">for</span> i <span class="keyword">in</span>  <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">101</span>):</span><br><span class="line"><span class="meta">... </span>        <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">101</span>):</span><br><span class="line"><span class="meta">... </span>           ws.cell(row=i, column=j)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h5 id="2-多单元格访问">2.多单元格访问</h5>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 通过切片</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>cell_range = ws[<span class="string">&#x27;A1&#x27;</span>:<span class="string">&#x27;C2&#x27;</span>]</span><br><span class="line"><span class="comment"># 通过行(列)</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>colC = ws[<span class="string">&#x27;C&#x27;</span>]</span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>col_range = ws[<span class="string">&#x27;C:D&#x27;</span>]</span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>row10 = ws[<span class="number">10</span>]</span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>row_range = ws[<span class="number">5</span>:<span class="number">10</span>]</span><br><span class="line"><span class="comment"># 通过指定范围(行 → 行)</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span><span class="keyword">for</span> row <span class="keyword">in</span>  ws.iter_rows(min_row=<span class="number">1</span>, max_col=<span class="number">3</span>, max_row=<span class="number">2</span>):</span><br><span class="line"><span class="meta">... </span>   <span class="keyword">for</span> cell <span class="keyword">in</span>  row:</span><br><span class="line"><span class="meta">... </span>       <span class="built_in">print</span>(cell)</span><br><span class="line">&lt;Cell Sheet1.A1&gt;</span><br><span class="line">&lt;Cell Sheet1.B1&gt;</span><br><span class="line">&lt;Cell Sheet1.C1&gt;</span><br><span class="line">&lt;Cell Sheet1.A2&gt;</span><br><span class="line">&lt;Cell Sheet1.B2&gt;</span><br><span class="line">&lt;Cell Sheet1.C2&gt;　</span><br><span class="line"><span class="comment"># 通过指定范围(列 → 列)</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span><span class="keyword">for</span> row <span class="keyword">in</span>  ws.iter_rows(min_row=<span class="number">1</span>, max_col=<span class="number">3</span>, max_row=<span class="number">2</span>):</span><br><span class="line"><span class="meta">... </span>   <span class="keyword">for</span> cell <span class="keyword">in</span>  row:</span><br><span class="line"><span class="meta">... </span>       <span class="built_in">print</span>(cell)</span><br><span class="line">&lt;Cell Sheet1.A1&gt;</span><br><span class="line">&lt;Cell Sheet1.B1&gt;</span><br><span class="line">&lt;Cell Sheet1.C1&gt;</span><br><span class="line">&lt;Cell Sheet1.A2&gt;</span><br><span class="line">&lt;Cell Sheet1.B2&gt;</span><br><span class="line">&lt;Cell Sheet1.C2&gt;</span><br><span class="line"><span class="comment"># 遍历所有 方法一</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>ws = wb.active</span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>ws[<span class="string">&#x27;C9&#x27;</span>] = <span class="string">&#x27;hello world&#x27;</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span><span class="built_in">tuple</span>(ws.rows)</span><br><span class="line">((&lt;Cell Sheet.A1&gt;, &lt;Cell Sheet.B1&gt;, &lt;Cell Sheet.C1&gt;),</span><br><span class="line">(&lt;Cell Sheet.A2&gt;, &lt;Cell Sheet.B2&gt;, &lt;Cell Sheet.C2&gt;),</span><br><span class="line">...</span><br><span class="line">(&lt;Cell Sheet.A8&gt;, &lt;Cell Sheet.B8&gt;, &lt;Cell Sheet.C8&gt;),</span><br><span class="line">(&lt;Cell Sheet.A9&gt;, &lt;Cell Sheet.B9&gt;, &lt;Cell Sheet.C9&gt;))</span><br><span class="line"><span class="comment"># 遍历所有 方法二</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span><span class="built_in">tuple</span>(ws.columns)</span><br><span class="line">((&lt;Cell Sheet.A1&gt;,</span><br><span class="line">&lt;Cell Sheet.A2&gt;,</span><br><span class="line">&lt;Cell Sheet.A3&gt;,</span><br><span class="line">...</span><br><span class="line">&lt;Cell Sheet.B7&gt;,</span><br><span class="line">&lt;Cell Sheet.B8&gt;,</span><br><span class="line">&lt;Cell Sheet.B9&gt;),</span><br><span class="line">(&lt;Cell Sheet.C1&gt;,</span><br><span class="line">...</span><br><span class="line">&lt;Cell Sheet.C8&gt;,</span><br><span class="line">&lt;Cell Sheet.C9&gt;))</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="四-存储数据">四 存储数据</h4>
<h5 id="1-给单元格赋值">1.给单元格赋值</h5>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 方式一：数据可以直接分配到单元格中(可以输入公式)</span></span><br><span class="line">ws[<span class="string">&#x27;A1&#x27;</span>] = <span class="number">42</span></span><br><span class="line"><span class="comment"># 方式二：可以附加行，从第一列开始附加(从最下方空白处，最左开始)(可以输入多行)</span></span><br><span class="line">ws.append([<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>])</span><br><span class="line"><span class="comment"># 方式三：Python 类型会被自动转换</span></span><br><span class="line">ws[<span class="string">&#x27;A3&#x27;</span>] = datetime.datetime.now().strftime(<span class="string">&quot;%Y-%m-%d&quot;</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h5 id="2-保存文件">2.保存文件</h5>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&gt;&gt;&gt; </span>wb.save(<span class="string">&#x27;文件名称.xlsx&#x27;</span>)</span><br></pre></td></tr></table></figure>
<h4 id="五-其他操作">五 其他操作</h4>
<h5 id="1-改变sheet标签按钮颜色">1.改变sheet标签按钮颜色</h5>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ws.sheet_properties.tabColor = <span class="string">&quot;1072BA&quot;</span></span><br></pre></td></tr></table></figure>
<h5 id="2-获取最大行最大列">2.获取最大行最大列</h5>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 获得最大列和最大行</span></span><br><span class="line"><span class="built_in">print</span>(sheet.max_row)</span><br><span class="line"><span class="built_in">print</span>(sheet.max_column)</span><br></pre></td></tr></table></figure>
<h5 id="3-获取每一行每一列">3.获取每一行每一列</h5>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#sheet.rows为生成器, 里面是每一行的数据，每一行又由一个tuple包裹。</span></span><br><span class="line"><span class="comment">#sheet.columns类似，不过里面是每个tuple是每一列的单元格。</span></span><br><span class="line"><span class="comment"># 因为按行，所以返回A1, B1, C1这样的顺序</span></span><br><span class="line"><span class="keyword">for</span> row <span class="keyword">in</span> sheet.rows:</span><br><span class="line">    <span class="keyword">for</span> cell <span class="keyword">in</span> row:</span><br><span class="line">        <span class="built_in">print</span>(cell.value)</span><br><span class="line"></span><br><span class="line"><span class="comment"># A1, A2, A3这样的顺序</span></span><br><span class="line"><span class="keyword">for</span> column <span class="keyword">in</span> sheet.columns:</span><br><span class="line">    <span class="keyword">for</span> cell <span class="keyword">in</span> column:</span><br><span class="line">        <span class="built_in">print</span>(cell.value)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h5 id="4-根据数字得到字母，根据字母得到数字">4.根据数字得到字母，根据字母得到数字</h5>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> openpyxl.utils <span class="keyword">import</span> get_column_letter, column_index_from_string</span><br><span class="line"></span><br><span class="line"><span class="comment"># 根据列的数字返回字母</span></span><br><span class="line"><span class="built_in">print</span>(get_column_letter(<span class="number">2</span>))  <span class="comment"># B</span></span><br><span class="line"><span class="comment"># 根据字母返回列的数字</span></span><br><span class="line"><span class="built_in">print</span>(column_index_from_string(<span class="string">&#x27;D&#x27;</span>))  <span class="comment"># 4</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h5 id="5-矩阵置换（行-→-列）">5.矩阵置换（行 → 列）</h5>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">rows = [</span><br><span class="line">    [<span class="string">&#x27;Number&#x27;</span>, <span class="string">&#x27;data1&#x27;</span>, <span class="string">&#x27;data2&#x27;</span>],</span><br><span class="line">    [<span class="number">2</span>, <span class="number">40</span>, <span class="number">30</span>],</span><br><span class="line">    [<span class="number">3</span>, <span class="number">40</span>, <span class="number">25</span>],</span><br><span class="line">    [<span class="number">4</span>, <span class="number">50</span>, <span class="number">30</span>],</span><br><span class="line">    [<span class="number">5</span>, <span class="number">30</span>, <span class="number">10</span>],</span><br><span class="line">    [<span class="number">6</span>, <span class="number">25</span>, <span class="number">5</span>],</span><br><span class="line">    [<span class="number">7</span>, <span class="number">50</span>, <span class="number">10</span>]]</span><br><span class="line"></span><br><span class="line"><span class="built_in">list</span>(<span class="built_in">zip</span>(*rows))</span><br><span class="line"></span><br><span class="line"><span class="comment"># out</span></span><br><span class="line">[(<span class="string">&#x27;Number&#x27;</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">7</span>),</span><br><span class="line"> (<span class="string">&#x27;data1&#x27;</span>, <span class="number">40</span>, <span class="number">40</span>, <span class="number">50</span>, <span class="number">30</span>, <span class="number">25</span>, <span class="number">50</span>),</span><br><span class="line"> (<span class="string">&#x27;data2&#x27;</span>, <span class="number">30</span>, <span class="number">25</span>, <span class="number">30</span>, <span class="number">10</span>, <span class="number">5</span>, <span class="number">10</span>)]</span><br><span class="line"></span><br><span class="line"><span class="comment"># 注意 方法会舍弃缺少数据的列(行)</span></span><br><span class="line">rows = [</span><br><span class="line">    [<span class="string">&#x27;Number&#x27;</span>, <span class="string">&#x27;data1&#x27;</span>, <span class="string">&#x27;data2&#x27;</span>],</span><br><span class="line">    [<span class="number">2</span>, <span class="number">40</span>	  ],	<span class="comment"># 这里少一个数据</span></span><br><span class="line">    [<span class="number">3</span>, <span class="number">40</span>, <span class="number">25</span>],</span><br><span class="line">    [<span class="number">4</span>, <span class="number">50</span>, <span class="number">30</span>],</span><br><span class="line">    [<span class="number">5</span>, <span class="number">30</span>, <span class="number">10</span>],</span><br><span class="line">    [<span class="number">6</span>, <span class="number">25</span>, <span class="number">5</span>],</span><br><span class="line">    [<span class="number">7</span>, <span class="number">50</span>, <span class="number">10</span>],</span><br><span class="line">]</span><br><span class="line"><span class="comment"># out</span></span><br><span class="line">[(<span class="string">&#x27;Number&#x27;</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">7</span>), (<span class="string">&#x27;data1&#x27;</span>, <span class="number">40</span>, <span class="number">40</span>, <span class="number">50</span>, <span class="number">30</span>, <span class="number">25</span>, <span class="number">50</span>)]</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="六-设置单元格样式">六 设置单元格样式</h4>
<h5 id="1-导入类">1.导入类</h5>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> openpyxl.styles <span class="keyword">import</span> Font, colors, Alignment</span><br></pre></td></tr></table></figure>
<h5 id="2-字体">2.字体</h5>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#下面的代码指定了等线24号，加粗斜体，字体颜色红色。直接使用cell的font属性，将Font对象赋值给它</span></span><br><span class="line">bold_itatic_24_font = Font(name=<span class="string">&#x27;等线&#x27;</span>, size=<span class="number">24</span>, italic=<span class="literal">True</span>, color=colors.RED, bold=<span class="literal">True</span>)</span><br><span class="line"></span><br><span class="line">sheet[<span class="string">&#x27;A1&#x27;</span>].font = bold_itatic_24_font</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h5 id="3-对齐方式">3.对齐方式</h5>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#也是直接使用cell的属性aligment，这里指定垂直居中和水平居中。除了center，还可以使用right、left等等参数。</span></span><br><span class="line"><span class="comment"># 设置B1中的数据垂直居中和水平居中</span></span><br><span class="line">sheet[<span class="string">&#x27;B1&#x27;</span>].alignment = Alignment(horizontal=<span class="string">&#x27;center&#x27;</span>, vertical=<span class="string">&#x27;center&#x27;</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h5 id="4-设置行高列宽">4.设置行高列宽</h5>
<h6 id="①-手动">① 手动</h6>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 第2行行高</span></span><br><span class="line">sheet.row_dimensions[<span class="number">2</span>].height = <span class="number">40</span></span><br><span class="line"><span class="comment"># C列列宽</span></span><br><span class="line">sheet.column_dimensions[<span class="string">&#x27;C&#x27;</span>].width = <span class="number">30</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h6 id="②-自动适应">② 自动适应</h6>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> openpyxl</span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">CXlAutofit</span>():</span><br><span class="line">    <span class="comment"># 生成列名字典，只是为了方便修改列宽时指定列，key:数字，从1开始；value:列名，从A开始</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">get_num_colnum_dict</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">        :return: 返回字典：&#123;1:&#x27;A&#x27;, 2:&#x27;B&#x27;, ...... , 52:&#x27;AZ&#x27;&#125;</span></span><br><span class="line"><span class="string">        &#x27;&#x27;&#x27;</span></span><br><span class="line">        num_str_dict = &#123;&#125;</span><br><span class="line">        A_Z = [<span class="built_in">chr</span>(a) <span class="keyword">for</span> a <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">ord</span>(<span class="string">&#x27;A&#x27;</span>), <span class="built_in">ord</span>(<span class="string">&#x27;Z&#x27;</span>) + <span class="number">1</span>)]</span><br><span class="line">        AA_AZ = [<span class="string">&#x27;A&#x27;</span> + <span class="built_in">chr</span>(a) <span class="keyword">for</span> a <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">ord</span>(<span class="string">&#x27;A&#x27;</span>), <span class="built_in">ord</span>(<span class="string">&#x27;Z&#x27;</span>) + <span class="number">1</span>)]</span><br><span class="line">        A_AZ = A_Z + AA_AZ</span><br><span class="line">        <span class="keyword">for</span> i <span class="keyword">in</span> A_AZ:</span><br><span class="line">            num_str_dict[A_AZ.index(i) + <span class="number">1</span>] = i</span><br><span class="line">        <span class="keyword">return</span> num_str_dict</span><br><span class="line">        </span><br><span class="line">    <span class="comment"># 自适应列宽</span></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">style_excel</span>(<span class="params">self,excel_name:<span class="built_in">str</span>,sheet_name:<span class="built_in">str</span></span>):</span><br><span class="line">        <span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">        :param sheet_name:  excel中的sheet名</span></span><br><span class="line"><span class="string">        :return:</span></span><br><span class="line"><span class="string">        &#x27;&#x27;&#x27;</span></span><br><span class="line">        <span class="comment"># 打开excel</span></span><br><span class="line">        wb = openpyxl.load_workbook(excel_name)</span><br><span class="line">        <span class="comment"># 选择对应的sheet</span></span><br><span class="line">        sheet = wb[sheet_name]</span><br><span class="line">        <span class="comment"># 获取最大行数与最大列数</span></span><br><span class="line">        max_column = sheet.max_column</span><br><span class="line">        max_row = sheet.max_row</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 将每一列，单元格列宽最大的列宽值存到字典里，key:列的序号从1开始(与字典num_str_dic中的key对应)；value:列宽的值</span></span><br><span class="line">        max_column_dict = &#123;&#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 生成列名字典，只是为了方便修改列宽时指定列，key:数字，从1开始；value:列名，从A开始</span></span><br><span class="line">        num_str_dict = self.get_num_colnum_dict()</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 遍历全部列</span></span><br><span class="line">        <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>, max_column + <span class="number">1</span>):</span><br><span class="line">            <span class="comment"># 遍历每一列的全部行</span></span><br><span class="line">            <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>, max_row + <span class="number">1</span>):</span><br><span class="line">                column = <span class="number">0</span></span><br><span class="line">                <span class="comment"># 获取j行i列的值</span></span><br><span class="line">                sheet_value = sheet.cell(row=j, column=i).value</span><br><span class="line">                <span class="comment"># 通过列表生成式生成字符列表，将当前获取到的单元格的str值的每一个字符放在一个列表中（列表中一个元素是一个字符）</span></span><br><span class="line">                sheet_value_list = [k <span class="keyword">for</span> k <span class="keyword">in</span> <span class="built_in">str</span>(sheet_value)]</span><br><span class="line">                <span class="comment"># 遍历当前单元格的字符列表</span></span><br><span class="line">                <span class="keyword">for</span> v <span class="keyword">in</span> sheet_value_list:</span><br><span class="line">                    <span class="comment"># 判定长度，一个数字或一个字母，单元格列宽+=1.1，其它+=2.2（长度可根据需要自行修改，经测试一个字母的列宽长度大概为1）</span></span><br><span class="line">                    <span class="keyword">if</span> v.isdigit() == <span class="literal">True</span> <span class="keyword">or</span> v.isalpha() == <span class="literal">True</span>:</span><br><span class="line">                        column += <span class="number">1.1</span></span><br><span class="line">                    <span class="keyword">else</span>:</span><br><span class="line">                        column += <span class="number">2.2</span></span><br><span class="line">                <span class="comment"># 当前单元格列宽与字典中的对比，大于字典中的列宽值则将字典更新。如果字典没有这个key，抛出异常并将值添加到字典中</span></span><br><span class="line">                <span class="keyword">try</span>:</span><br><span class="line">                    <span class="keyword">if</span> column &gt; max_column_dict[i]:</span><br><span class="line">                        max_column_dict[i] = column</span><br><span class="line">                <span class="keyword">except</span> Exception <span class="keyword">as</span> e:</span><br><span class="line">                    max_column_dict[i] = column</span><br><span class="line">        <span class="comment"># 此时max_column_dict字典中已存有当前sheet的所有列的最大列宽值，直接遍历字典修改列宽</span></span><br><span class="line">        <span class="keyword">for</span> key, value <span class="keyword">in</span> max_column_dict.items():</span><br><span class="line">            sheet.column_dimensions[num_str_dict[key]].width = value</span><br><span class="line">        <span class="comment"># 保存</span></span><br><span class="line">        wb.save(excel_name)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 调用方法 实例化类</span></span><br><span class="line">Entity = CXlAutofit()</span><br><span class="line"><span class="comment"># 传入参数：Excel名称，需要设置列宽的Sheet名称</span></span><br><span class="line">Entity.style_excel(<span class="string">&#x27;excelTest.xlsx&#x27;</span>,<span class="string">&#x27;Sheet1&#x27;</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h5 id="5-合并拆分单元格">5.合并拆分单元格</h5>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 所谓合并单元格，即以合并区域的左上角的那个单元格为基准，覆盖其他单元格使之称为一个大的单元格。</span></span><br><span class="line"><span class="comment"># 相反，拆分单元格后将这个大单元格的值返回到原来的左上角位置。</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 合并单元格， 往左上角写入数据即可</span></span><br><span class="line">sheet.merge_cells(<span class="string">&#x27;B1:G1&#x27;</span>) <span class="comment"># 合并一行中的几个单元格</span></span><br><span class="line">sheet.merge_cells(<span class="string">&#x27;A1:C3&#x27;</span>) <span class="comment"># 合并一个矩形区域中的单元格</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 合并后只可以往左上角写入数据，也就是区间中:左边的坐标。</span></span><br><span class="line"><span class="comment"># 如果这些要合并的单元格都有数据，只会保留左上角的数据，其他则丢弃。换句话说若合并前不是在左上角写入数据，合并后单元格中不会有数据。</span></span><br><span class="line"><span class="comment"># 以下是拆分单元格的代码。拆分后，值回到A1位置。</span></span><br><span class="line">sheet.unmerge_cells(<span class="string">&#x27;A1:C3&#x27;</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id=""></h4>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://Sep2Seven.blog.com">Sep2Seven</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://sep2seven.blog.com/2023/06/08/ExcelOpenpyxl/">http://sep2seven.blog.com/2023/06/08/ExcelOpenpyxl/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://Sep2Seven.blog.com" target="_blank">Sep2Sevem'blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Python/">Python</a><a class="post-meta__tags" href="/tags/Openpyxl/">Openpyxl</a></div><div class="post_share"><div class="social-share" data-image="/img/yanhua.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/img/weChat.jpg" target="_blank"><img class="post-qr-code-img" src="/img/weChat.jpg" alt="wechat"/></a><div class="post-qr-code-desc">wechat</div></li><li class="reward-item"><a href="/img/zhifubao.jpg" target="_blank"><img class="post-qr-code-img" src="/img/zhifubao.jpg" alt="alipay"/></a><div class="post-qr-code-desc">alipay</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-full"><a href="/2023/06/08/python%E6%A0%BC%E5%BC%8F%E7%9B%B8%E4%BA%92%E8%BD%AC%E6%8D%A2/" title="python格式相互转换"><img class="cover" src="/img/mingzuo.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">python格式相互转换</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2023/06/08/python%E6%A0%BC%E5%BC%8F%E7%9B%B8%E4%BA%92%E8%BD%AC%E6%8D%A2/" title="python格式相互转换"><img class="cover" src="/img/mingzuo.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-06-08</div><div class="title">python格式相互转换</div></div></a></div><div><a href="/2023/06/08/python%E7%88%AC%E8%99%AB%E4%B9%8B%E5%A4%84%E7%90%86%E7%AE%80%E5%8D%95%E5%9B%BE%E7%89%87%E9%AA%8C%E8%AF%81%E7%A0%81/" title="python爬虫之百度识别图片API"><img class="cover" src="/img/mingzuo.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-06-08</div><div class="title">python爬虫之百度识别图片API</div></div></a></div></div></div><hr class="custom-hr"/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/boniu.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Sep2Seven</div><div class="author-info__description">背着昨天追赶明天，却累坏了今天</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">4</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">8</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/Sep2Seven/sep2-seven-blog"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/Sep2Seven" target="_blank" title="Gitee"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="/1074209561@qq.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">祝贺Sep2Seven个人博客开始起航</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%B8%80-%E5%AE%89%E8%A3%85"><span class="toc-number">1.</span> <span class="toc-text">一 安装</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BA%8C-%E6%89%93%E5%BC%80%E6%96%87%E4%BB%B6%EF%BC%88%E5%8F%AA%E6%94%AF%E6%8C%81xlsx%E6%A0%BC%E5%BC%8F%EF%BC%89"><span class="toc-number">2.</span> <span class="toc-text">二 打开文件（只支持xlsx格式）</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1-%E5%88%9B%E5%BB%BA"><span class="toc-number">2.1.</span> <span class="toc-text">1.创建</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-%E6%89%93%E5%BC%80%E5%B7%B2%E6%9C%89%E6%96%87%E4%BB%B6"><span class="toc-number">2.2.</span> <span class="toc-text">2.打开已有文件</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%B8%89-%E8%A1%A8%EF%BC%88sheet%EF%BC%89"><span class="toc-number">3.</span> <span class="toc-text">三 表（sheet）</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1-%E5%88%9B%E5%BB%BA%E8%A1%A8"><span class="toc-number">3.1.</span> <span class="toc-text">1.创建表</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#3-%E5%88%A0%E9%99%A4%E8%A1%A8"><span class="toc-number">3.2.</span> <span class="toc-text">3.删除表</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-%E9%80%89%E6%8B%A9%E8%A1%A8"><span class="toc-number">3.3.</span> <span class="toc-text">2.选择表</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#3-%E6%9F%A5%E7%9C%8B%E8%A1%A8%E5%90%8D"><span class="toc-number">3.4.</span> <span class="toc-text">3.查看表名</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%B8%89-%E5%8D%95%E5%85%83%E6%A0%BC"><span class="toc-number">4.</span> <span class="toc-text">三 单元格</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1-%E5%8D%95%E4%B8%80%E5%8D%95%E5%85%83%E6%A0%BC%E8%AE%BF%E9%97%AE"><span class="toc-number">4.1.</span> <span class="toc-text">1.单一单元格访问</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-%E5%A4%9A%E5%8D%95%E5%85%83%E6%A0%BC%E8%AE%BF%E9%97%AE"><span class="toc-number">4.2.</span> <span class="toc-text">2.多单元格访问</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%9B%9B-%E5%AD%98%E5%82%A8%E6%95%B0%E6%8D%AE"><span class="toc-number">5.</span> <span class="toc-text">四 存储数据</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1-%E7%BB%99%E5%8D%95%E5%85%83%E6%A0%BC%E8%B5%8B%E5%80%BC"><span class="toc-number">5.1.</span> <span class="toc-text">1.给单元格赋值</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-%E4%BF%9D%E5%AD%98%E6%96%87%E4%BB%B6"><span class="toc-number">5.2.</span> <span class="toc-text">2.保存文件</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BA%94-%E5%85%B6%E4%BB%96%E6%93%8D%E4%BD%9C"><span class="toc-number">6.</span> <span class="toc-text">五 其他操作</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1-%E6%94%B9%E5%8F%98sheet%E6%A0%87%E7%AD%BE%E6%8C%89%E9%92%AE%E9%A2%9C%E8%89%B2"><span class="toc-number">6.1.</span> <span class="toc-text">1.改变sheet标签按钮颜色</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-%E8%8E%B7%E5%8F%96%E6%9C%80%E5%A4%A7%E8%A1%8C%E6%9C%80%E5%A4%A7%E5%88%97"><span class="toc-number">6.2.</span> <span class="toc-text">2.获取最大行最大列</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#3-%E8%8E%B7%E5%8F%96%E6%AF%8F%E4%B8%80%E8%A1%8C%E6%AF%8F%E4%B8%80%E5%88%97"><span class="toc-number">6.3.</span> <span class="toc-text">3.获取每一行每一列</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#4-%E6%A0%B9%E6%8D%AE%E6%95%B0%E5%AD%97%E5%BE%97%E5%88%B0%E5%AD%97%E6%AF%8D%EF%BC%8C%E6%A0%B9%E6%8D%AE%E5%AD%97%E6%AF%8D%E5%BE%97%E5%88%B0%E6%95%B0%E5%AD%97"><span class="toc-number">6.4.</span> <span class="toc-text">4.根据数字得到字母，根据字母得到数字</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#5-%E7%9F%A9%E9%98%B5%E7%BD%AE%E6%8D%A2%EF%BC%88%E8%A1%8C-%E2%86%92-%E5%88%97%EF%BC%89"><span class="toc-number">6.5.</span> <span class="toc-text">5.矩阵置换（行 → 列）</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%85%AD-%E8%AE%BE%E7%BD%AE%E5%8D%95%E5%85%83%E6%A0%BC%E6%A0%B7%E5%BC%8F"><span class="toc-number">7.</span> <span class="toc-text">六 设置单元格样式</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1-%E5%AF%BC%E5%85%A5%E7%B1%BB"><span class="toc-number">7.1.</span> <span class="toc-text">1.导入类</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-%E5%AD%97%E4%BD%93"><span class="toc-number">7.2.</span> <span class="toc-text">2.字体</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#3-%E5%AF%B9%E9%BD%90%E6%96%B9%E5%BC%8F"><span class="toc-number">7.3.</span> <span class="toc-text">3.对齐方式</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#4-%E8%AE%BE%E7%BD%AE%E8%A1%8C%E9%AB%98%E5%88%97%E5%AE%BD"><span class="toc-number">7.4.</span> <span class="toc-text">4.设置行高列宽</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#%E2%91%A0-%E6%89%8B%E5%8A%A8"><span class="toc-number">7.4.1.</span> <span class="toc-text">① 手动</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E2%91%A1-%E8%87%AA%E5%8A%A8%E9%80%82%E5%BA%94"><span class="toc-number">7.4.2.</span> <span class="toc-text">② 自动适应</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#5-%E5%90%88%E5%B9%B6%E6%8B%86%E5%88%86%E5%8D%95%E5%85%83%E6%A0%BC"><span class="toc-number">7.5.</span> <span class="toc-text">5.合并拆分单元格</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">8.</span> <span class="toc-text"></span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2023/06/08/ExcelOpenpyxl/" title="Excel处理之Openpyxl库"><img src="/img/yanhua.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Excel处理之Openpyxl库"/></a><div class="content"><a class="title" href="/2023/06/08/ExcelOpenpyxl/" title="Excel处理之Openpyxl库">Excel处理之Openpyxl库</a><time datetime="2023-06-08T08:50:33.000Z" title="发表于 2023-06-08 16:50:33">2023-06-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/06/08/python%E6%A0%BC%E5%BC%8F%E7%9B%B8%E4%BA%92%E8%BD%AC%E6%8D%A2/" title="python格式相互转换"><img src="/img/mingzuo.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="python格式相互转换"/></a><div class="content"><a class="title" href="/2023/06/08/python%E6%A0%BC%E5%BC%8F%E7%9B%B8%E4%BA%92%E8%BD%AC%E6%8D%A2/" title="python格式相互转换">python格式相互转换</a><time datetime="2023-06-08T08:50:33.000Z" title="发表于 2023-06-08 16:50:33">2023-06-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/06/08/python%E7%88%AC%E8%99%AB%E4%B9%8B%E5%A4%84%E7%90%86%E7%AE%80%E5%8D%95%E5%9B%BE%E7%89%87%E9%AA%8C%E8%AF%81%E7%A0%81/" title="python爬虫之百度识别图片API"><img src="/img/mingzuo.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="python爬虫之百度识别图片API"/></a><div class="content"><a class="title" href="/2023/06/08/python%E7%88%AC%E8%99%AB%E4%B9%8B%E5%A4%84%E7%90%86%E7%AE%80%E5%8D%95%E5%9B%BE%E7%89%87%E9%AA%8C%E8%AF%81%E7%A0%81/" title="python爬虫之百度识别图片API">python爬虫之百度识别图片API</a><time datetime="2023-06-08T08:50:33.000Z" title="发表于 2023-06-08 16:50:33">2023-06-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/06/08/Stream/" title="Stream流式处理"><img src="/img/yanhua.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Stream流式处理"/></a><div class="content"><a class="title" href="/2023/06/08/Stream/" title="Stream流式处理">Stream流式处理</a><time datetime="2023-06-08T07:50:33.000Z" title="发表于 2023-06-08 15:50:33">2023-06-08</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('/img/yanhua.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2023 By Sep2Seven</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="chat-btn" type="button" title="聊天"><i class="fas fa-sms"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: 'EWW1EB1JHC3Trd4CP5Z6117W-gzGzoHsz',
      appKey: 'o7BwNBQKxTkjcqr8XBWekurc',
      avatar: 'monsterid',
      serverURLs: '',
      emojiMaps: "",
      path: window.location.pathname,
      visitor: true
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><div class="aplayer no-destroy" data-id="60198" data-server="netease" data-type="playlist" data-fixed="true" data-autoplay="true"> </div><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="188" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-nest.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-show-text" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-show-text.min.js" data-mobile="false" data-text="学无止境,力争上游,聚沙成塔,笨鸟先飞,勤学好问,有志竟成,绳锯木断,夕寐宵兴,搦朽磨钝" data-fontsize="15px" data-random="false" async="async"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/metingjs/dist/Meting.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div class="no-result" id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div></body></html>